﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using QBZ.Evaluation.Domains;
using QBZ.Evaluation.Models;

namespace QBZ.Evaluation.Views.Controllers
{
    //[EnableCors("any")]
    [Route("api/[controller]/[action]/{id?}")]
    [ApiController]
    [Authorize]
    public class SkillController : Controller
    {
        private SkillDomain _skill;

        public SkillController(SkillDomain skill)
        {
            _skill = skill;
        }

        [HttpPost]
        public ActionResult<ResponseModel> AddSkillParent([FromForm]SkillParentModel skillParent)
        {
            return new ResponseModel(_skill.AddSkillParent(skillParent) ? ErrReason.Ok : ErrReason.UnknownError);
        }
        [HttpPost]
        public ActionResult<ResponseModel> AddSkill([FromForm]SkillModel skillParent)
        {
            return new ResponseModel(_skill.AddSkill(skillParent) ? ErrReason.Ok : ErrReason.UnknownError);
        }

        [HttpPost,HttpGet]
        public ActionResult<ResponseModel> GetSkillParents()
        {
            var res = new ResponseModel(ErrReason.Ok);
            res.result = _skill.GetSkillParents();
            return res;
        }

        [HttpPost]
        public ActionResult<ResponseModel> EditSkillParent([FromForm]SkillParentModel skillParent)
        {
            return new ResponseModel(_skill.EditSkillParent(skillParent) ? ErrReason.Ok : ErrReason.UnknownError);
        }

        [HttpPost]
        public ActionResult<ResponseModel> EditSkill([FromForm]SkillModel skill)
        {
            return new ResponseModel(_skill.EditSkill(skill) ? ErrReason.Ok : ErrReason.UnknownError);
        }

        [HttpPost]
        public ActionResult<ResponseModel> EditSkillDetail([FromForm]SkillChildModel skillChild)
        {
            return new ResponseModel(_skill.EditSkillDetail(skillChild) ? ErrReason.Ok : ErrReason.UnknownError);
        }

        [HttpPost]
        public ActionResult<ResponseModel> DeleteSkillDetail([FromForm]int skillDetailId)
        {
            return new ResponseModel(_skill.DeleteSkillDetail(skillDetailId) ? ErrReason.Ok : ErrReason.UnknownError);
        }

        [HttpPost]
        public ActionResult<ResponseModel> DeleteSkillParent([FromForm]int skillParentId)
        {
            return new ResponseModel(_skill.DeleteSkillParent(skillParentId) ? ErrReason.Ok : ErrReason.UnknownError);
        }

        [HttpPost]
        public ActionResult<ResponseModel> DeleteSkill([FromForm]int skillId)
        {
            return new ResponseModel(_skill.DeleteSkill(skillId) ? ErrReason.Ok : ErrReason.UnknownError);
        }

        [HttpPost]
        public ActionResult<ResponseModel> GetSkills([FromForm]int parentId = 0)
        {
            var res = new ResponseModel(ErrReason.Ok);
            res.result = _skill.GetSkills(parentId);
            return res;
        }

        [HttpPost]
        public ActionResult<ResponseModel> GetSkillDetails([FromForm]int skillId)
        {
            var res = new ResponseModel(ErrReason.Ok);
            res.result = _skill.GetSkillDetails(skillId);
            return res;
        }

        [HttpPost]
        public ActionResult<ResponseModel> AddSkillDetail([FromForm]SkillChildModel skillChild)
        {
            return new ResponseModel(_skill.AddSkillDetail(skillChild) ? ErrReason.Ok : ErrReason.UnknownError);
        }

        [HttpPost]
        public ActionResult<ResponseModel> MoveSkill([FromForm]SkillModel skillModel)
        {
            return new ResponseModel(_skill.MoveSkill(skillModel) ? ErrReason.Ok : ErrReason.UnknownError);
        }
        [HttpPost]
        public ActionResult<ResponseModel> MoveSkillDetail([FromForm]SkillChildModel skillChild)
        {
            return new ResponseModel(_skill.MoveSkillDetail(skillChild) ? ErrReason.Ok : ErrReason.UnknownError);
        }

        [HttpPost]
        public ActionResult<ResponseModel> CopySkillWithDetail([FromForm]SkillModel skillModel)
        {
            return new ResponseModel(_skill.CopySkillWithDetail(skillModel) ? ErrReason.Ok : ErrReason.UnknownError);
        }

        [HttpPost]
        public ActionResult<ResponseModel> GetAll()
        {
            var res = new ResponseModel( ErrReason.Ok);
            res.result = new { Parents = _skill.GetSkillParents(), Skills = _skill.GetSkills() };
            return res;
        }

    }
}